package com.seadragon.app.ksr.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.seadragon.app.ksr.model.tiger.Location;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Point;


//@AnalyzerDef(name = "addressanalyzer", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = {
//	@TokenFilterDef(factory = LowerCaseFilterFactory.class),
//	@TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = { @Parameter(name = "language", value = "English") }) })
@Entity
//@Indexed(index = "Address")
//@Spatial(name="location")
@Table(name = "ADDRESS", schema="STAGING")
public class Address extends Location {
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ADDRESSIDSEQ")
	@SequenceGenerator(name = "ADDRESSIDSEQ", sequenceName = "STAGING.ADDRESS_ID_SEQ", schema="STAGING")	
	private long id;

	@Column(name="ADDRESS_NAME")
	private String addressName;

	@Column(name = "ADDRESS_LINE1")
//	@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
	private String addressLine1;

	@Column(name="STREET_NUMBER")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String streetNumber;
	
	@Column(name="STREET_NAME")
//	@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
	private String streetName;
	
	@Column(name = "ADDRESS_LINE2")
	private String addressLine2;

	@Column(name="STREET_TYPE")
	private String streetType;

	@Column(name = "CITY")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String city;
	
	@Column(name = "STATE")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String state;
	
	@Column(name = "ZIP")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String zip;

	@Column(name = "NEIGHBORHOOD")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String neighborhood;

	@Column(name = "COORD")
	@Type(type = "org.hibernate.spatial.GeometryType")
	private Point location;
	
	@Column(name = "PREDIR")
	private String preDir;
	
	@Column(name = "POSTDIR")
	private String postDir;
	
	@Column(name = "INTERNAL")
	private String internal;
	
	@Column(name="VALID")
	private boolean valid;
	
	@Column(name="ADDRESS_TYPE")
	private AddressType addressType;
	
	@Column(name = "GEOCODED_CITY")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String geocodedCity;

	@Column(name = "GEOCODED_COUNTY")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String geocodedCounty;

	@Column(name = "GEOCODED_STATE")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String geocodedState;

	@Column(name = "GEOCODED_ZIP")
//	@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
	private String geocodedZip;
	
	@Column(name = "COMPLETE_ADDRESS")
	private String completeAddress;
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public AddressType getAddressType() {
		return addressType;
	}

	public void setAddressType(AddressType addressType) {
		this.addressType = addressType;
	}

	public String getAddressName() {
		return addressName;
	}

	public void setAddressName(String addressName) {
		this.addressName = addressName;
	}

	public String getStreetNumber() {
		return streetNumber;
	}

	public void setStreetNumber(String streetNumber) {
		this.streetNumber = streetNumber;
	}

	public String getStreetName() {
		return streetName;
	}

	public void setStreetName(String streetName) {
		this.streetName = streetName;
	}

	public String getStreetType() {
		return streetType;
	}

	public void setStreetType(String streetType) {
		this.streetType = streetType;
	}

	public String getAddressLine1() {
		return addressLine1;
	}

	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}

	public String getAddressLine2() {
		return addressLine2;
	}

	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}

	public String getPreDir() {
		return preDir;
	}

	public void setPreDir(String preDir) {
		this.preDir = preDir;
	}

	public String getPostDir() {
		return postDir;
	}

	public void setPostDir(String postDir) {
		this.postDir = postDir;
	}

	public String getInternal() {
		return internal;
	}

	public void setInternal(String internal) {
		this.internal = internal;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getNeighborhood() {
		return neighborhood;
	}

	public void setNeighborhood(String neighborhood) {
		this.neighborhood = neighborhood;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public Point getLocation() {
		return location;
	}

	public void setLocation(Point location) {
		this.location = location;
	}

	@Override
	public Double getLatitude() {
		return location.getY();
	}

	@Override
	public Double getLongitude() {
		return location.getX();
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}
	
	public String getGeocodedCity() {
		return geocodedCity;
	}

	public void setGeocodedCity(String geocodedCity) {
		this.geocodedCity = geocodedCity;
	}

	public String getGeocodedCounty() {
		return geocodedCounty;
	}

	public void setGeocodedCounty(String geocodedCounty) {
		this.geocodedCounty = geocodedCounty;
	}

	public String getGeocodedState() {
		return geocodedState;
	}

	public void setGeocodedState(String geocodedState) {
		this.geocodedState = geocodedState;
	}

	public String getGeocodedZip() {
		return geocodedZip;
	}

	public void setGeocodedZip(String geocodedZip) {
		this.geocodedZip = geocodedZip;
	}

	public String getCompleteAddress() {
		return completeAddress;
	}

	public void setCompleteAddress(String completeAddress) {
		this.completeAddress = completeAddress;
	}

	public String toRawString(){
		StringBuilder sb = new StringBuilder(addressLine1);
		sb.append(", ");
		sb.append(city);
		sb.append(", ");
		sb.append(state);
		sb.append(" ");
		sb.append(zip);
		return sb.toString();
	}
	
	public String toGeocodedString() {
		StringBuilder sb = new StringBuilder(streetNumber);
		sb.append(", ");
		if(preDir != null){
			sb.append(preDir);
		}
		sb.append(", ");
		sb.append(streetName);
		sb.append(", ");
		sb.append(streetType);
		sb.append(", ");
		if(postDir != null){
			sb.append(postDir);
		}
		sb.append(geocodedCity);
		sb.append(", ");
		sb.append(geocodedCounty);
		sb.append(", ");
		sb.append(geocodedState);
		sb.append(", ");
		sb.append(geocodedZip);
		return sb.toString();
	}

	@Override
	public String getName() {
		return completeAddress;
	}

	@Override
	public MultiPolygon getGeom() {
		return null;
	}

	@Override
	public AddressType getLocationType() {
		return addressType;
	}

	@Override
	public String getStatefp() {
		return null;
	}
}
